package com.ada.demo;

public class TestStatic {
    public static void main(String[] args) {
        Child child1 = new Child("tom");
        child1.joinGame();


        Child child2 = new Child("jack");
        child2.joinGame();


        Child child3 = new Child("mary");
        child3.joinGame();

        System.out.println("共有" + Child.total);
    }
}

class Child {
    public String name;
    //静态变量
    public static int total = 0;

    public Child(String name) {
        this.name = name;
    }

    public void joinGame() {
        System.out.println(this.name + "加入游戏了");
        total++;
    }
}
